﻿using Microsoft.Extensions.Caching.Memory;

namespace RndMaterialDisposalService.Cache
{
    public interface ICacheContext
    {
        /// <summary>
        /// 获取缓存项
        /// </summary>
        /// <typeparam name="T">缓存对象类型<peparam>
        /// <param name="key">键</param>
        /// <returns>缓存对象</returns>
        public T Get<T>(string key);

        /// <summary>
        /// 设置缓存项
        /// </summary>
        /// <typeparam name="T">缓存对象类型<peparam>
        /// <param name="key">键</param>
        /// <param name="t">缓存对象</param>
        /// <returns>true成功,false失败</returns>
        public  bool Set<T>(string key, T t, DateTime expire);

        /// <summary>
        /// 获取缓存项
        /// </summary>
        /// <typeparam name="T">缓存对象类型</typeparam>
        /// <param name="key">键</param>
        /// <param name="t">缓存对象</param>
        /// <param name="memoryCacheEntryOptions">
        /// 缓存设置
        /// 设置滑动过期
        ///SlidingExpiration = new TimeSpan(2,0,0),
        ///设置缓存的优先级，当我们缓存空间不足的时候会移除等级低的缓存，以此类推（清除的时候不会管是否过期）
        ///Low,    低的意思,Normal, 正常模式  默认模式,High,   高,NeverRemove 绝不回收，这个就算内存满了也不会清除。
        ///Priority = CacheItemPriority.NeverRemove
        /// </param>
        /// <returns></returns>
        public bool Set<T>(string key, T t, MemoryCacheEntryOptions memoryCacheEntryOptions);

        /// <summary>
        /// 移除一个缓存项
        /// </summary>
        /// <param name="key">缓存项key</param>
        /// <returns>true成功,false失败</returns>
        public  bool Remove(string key);
    }
}
